import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:wallpaper/components/appbar_base.dart';
import 'package:wallpaper/generated/l10n.dart';
import 'package:wallpaper/themes/localization_info.dart';

class LocalizationsPage extends StatefulWidget {
  const LocalizationsPage({super.key});

  @override
  State<LocalizationsPage> createState() => _LocalizationsPageState();
}

// ignore: camel_case_types
class localItem {
  final String title;
  final String localeKey;
  const localItem(this.title, this.localeKey);
}

class _LocalizationsPageState extends State<LocalizationsPage> {
  @override
  Widget build(BuildContext context) {
    final localization = Provider.of<LocalizationInfo>(context);
    List<localItem> localList = [
      const localItem('简体中文', 'zh_CN'),
      const localItem('English', 'en'),
    ];
    return Scaffold(
      appBar: AppbarBase(title: S.of(context).internationalization),
      body: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Flex(
          direction: Axis.vertical,
          spacing: 8,
          children: [
            for (var item in localList)
              Material(
                  color: Theme.of(context).colorScheme.primaryContainer,
                  borderRadius: BorderRadius.circular(8),
                  clipBehavior: Clip.antiAlias,
                  child: ListTile(
                    title: Text(item.title),
                    // 右侧图标
                    trailing: localization.localeKey == item.localeKey
                        ? Icon(
                            Icons.check,
                            color: Theme.of(context).colorScheme.primary,
                          )
                        : null,
                    onTap: () {
                      localization.setLocaleKey(item.localeKey);
                    },
                  )),
          ],
        ),
      ),
    );
  }
}
